package com.lyk.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.common.dao.BaseDao;
import com.common.entity.A_assetLv;
import com.lyk.dao.A_assetLvDao;

public class A_assetLvDaoImpl extends BaseDao<A_assetLv> implements A_assetLvDao {

	@Override
	/**
	 * @author ע�⣺ʹ��ʱmp��key����Ϊ���������
	 * @author ����Ϊ������Բ����������
	 * @param Integer assetLv_id, String assetLv_name, Double min_assets, Double max_assets
	 */
	public List<A_assetLv> findByCondition(Map<String, Object> mp) {
		List<Object> pList = new ArrayList<Object>();
		StringBuffer sb = new StringBuffer(" select * from a_assetLv  where 1=1 ");	
		if(mp!=null&&mp.size()>0)
			for(Entry<String, Object> et:mp.entrySet()){
				sb.append("and "+et.getKey()+" = ? ");
				pList.add(et.getValue());
			}
		return findBySql(sb.toString(), pList.toArray());
	}

	@Override
	public A_assetLv findById(int id) {
		String sql = " select * from A_assetLv where assetLv_id = ? ";
		Object[] obj = {id};
		List<A_assetLv> lg = findBySql(sql, obj);
		return (lg!=null&&lg.size()>0)?lg.get(0):null;
	}

	@Override
	public int updateA_assetLv(Map<String, Object> mp) {
		String sql = "update A_assetLv set assetLv_name=?, min_assets=?, max_assets=? where assetLv_id=?";
		Object[] objs = {mp.get("assetLv_name"),mp.get("min_assets"),mp.get("max_assets"),mp.get("assetLv_id")};
		return executeUpdate(sql, objs);
	}

	@Override
	public int deleteA_assetLv(int id) {
		String sql = "delete from A_assetLv where assetLv_id=?";
		Object[] objs = {id};
		return executeUpdate(sql, objs);
	}

	@Override
	public int addA_assetLv(Map<String, Object> mp) {
		String sql = "insert into A_assetLv values(SEQ_A_ASSETLV.nextval,?,?,?)";
		Object[] objs = {mp.get("assetLv_name"),mp.get("min_assets"),mp.get("max_assets")};
		return executeUpdate(sql, objs);
	}

	@Override
	public A_assetLv getEntity(ResultSet rs) {
		A_assetLv a = new A_assetLv();
		try {
			a.setAssetLv_id(rs.getInt("assetLv_id"));
			a.setAssetLv_name(rs.getString("assetLv_name"));
			a.setMin_assets(rs.getDouble("min_assets"));
			a.setMax_assets(rs.getDouble("max_assets"));
			return a;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

}
